package com.yonyougov.devops.cruxcisupport.deployhistory;

import com.yonyougov.devops.cruxcisupport.deployhistory.dto.DeployHisPageLikeDto;
import com.yonyougov.devops.cruxcisupport.deployhistory.dto.DeployHisPageLikeRequestDto;
import com.yonyougov.devops.cruxcisupport.deployhistory.vo.DeployHisPageLikeVo;
import com.yonyougov.devops.fwc.api.dto.BaseResponseDto;
import com.yonyougov.devops.fwc.core.controller.CrudController;
import com.yonyougov.devops.fwc.core.entity.Pagination;
import com.yonyougov.devops.fwc.core.service.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigInteger;

/**
* Created by ligson on 2017/8/11.
*/
@Api(tags = "历史模块->部署历史")
@RestController
@RequestMapping("/api/v2/deployhis")
public class DeployHisController extends CrudController<DeployHisEntity, BigInteger> {

    private final DeployHisService deployHisService;

    public DeployHisController(DeployHisService deployHisService) {
        this.deployHisService = deployHisService;
    }

    @Override
    public BaseService<DeployHisEntity, BigInteger> getService() {
        return deployHisService;
    }

    //<!--用户自定义代码开始-->
    @ApiOperation(value = "历史模块-部署历史查询调用", notes = "历史模块-部署历史查询调用")
    @PostMapping(value = "/dh/page/like")
    public BaseResponseDto findCommitTestPageLike(@RequestBody @Valid DeployHisPageLikeRequestDto request) {
        DeployHisPageLikeDto deployHisPageLikeDto = new DeployHisPageLikeDto();
        BeanUtils.copyProperties(request,deployHisPageLikeDto);

        Pagination<DeployHisPageLikeVo> pagination = deployHisService.findDeployHisPageLike(deployHisPageLikeDto);

        BaseResponseDto result = BaseResponseDto.getSuccessInstance();
        result.put("totalCount", pagination.getTotalCount());
        result.put("data", pagination.getDatas());
        return result;
    }
    //<!--用户自定义代码结束-->
}
